package com.zengdada.authority.service.impl;

import com.zengdada.authority.config.security.intercept.AuthorityUtil;
import com.zengdada.authority.exception.RoutineException;
import com.zengdada.authority.model.AppUser;
import com.zengdada.authority.model.TimedTaskCron;
import com.zengdada.authority.service.EnhanceBaseService;
import com.zengdada.authority.service.TimedTaskCronAuthorityService;
import com.zengdada.authority.utils.CommonUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @Auther: 12614
 * @Contact: 1261438511@qq.com
 * @Date: 2019-03-29 14:22
 * @Description:
 */
@Service
public class TimedTaskCronAuthorityServiceImpl extends EnhanceBaseService<TimedTaskCron> implements TimedTaskCronAuthorityService {
    @Autowired
    AuthorityUtil authorityUtil;

    @Override
    public void save(TimedTaskCron timedTaskCron) {
        AppUser user = authorityUtil.getLoginUser();
        timedTaskCron.setModifyTime(new Date());
        timedTaskCron.setModifyUser(user.getId());
        if (StringUtils.isBlank(timedTaskCron.getId())) {
            try {
                CommonUtils.reflectObjectTransString(timedTaskCron, false);
            } catch (Exception e) {
                throw new RoutineException(e.getMessage());
            }
            this.add(timedTaskCron);
        } else {
            this.updateById(timedTaskCron);
        }
    }
}
